<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset=utf-8>
  <meta http-equiv=X-UA-Compatible content="IE=edge">
  <meta name=viewport content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
  <link rel=icon href=favicon.ico>
  <title>找一找</title>
  <link rel="stylesheet" href="./css/index.css">
</head>
<body>
  
  <div class="mainBox">
    <!-- <div class="topBg"></div> -->
    <img style='width:100%;' src="./images/app1.jpg" alt="">
    <img style='width:100%;margin-bottom:160px!important;' src="./images/app2.jpg" alt="" >
    <div class="bottomBtn">
      <input type="number" placeholder="请输入手机号" id="mobild">
      <button id="btn">绑定并下载</button>
    </div>
  </div>
  <div class="openIt" id='shadow'>
    <div class="inBox">
      <div>点击右上角菜单</div>
      <div>请在 <span style="color:#fdca03;">浏览器</span> 中打开链接</div>
    </div>
    <div class="arrow"></div>
  </div>
  <div class="openApp">
    <div class="imgBox">
      <a class="btnS" id="openApp" href="findit://">打开APP</a>
    </div>
  </div>
  <div class="downloadApp">
    <div class="imgBox">
      <!-- <a class="btnS" id="dApp" download href="https://find-server.oss-cn-hangzhou.aliyuncs.com/picture/find.apk">下载APP</a> -->
      <a class="btnS" id="dApp" download href="https://find-server.oss-cn-hangzhou.aliyuncs.com/picture/find.apk">下载APP</a>
    </div>
  </div>
</body>
<script src="./js/jquery-3.5.1.min.js"></script>
<script>
  function isWeixin() { //判断是否是微信
    var ua = navigator.userAgent.toLowerCase();
    return ua.match(/MicroMessenger/i) == "micromessenger";
  };
  if(isWeixin()){
    var shadow = document.getElementById('shadow');
    shadow.style.display = 'block';
  }
  function getSearchString(key, Url) {
    var str = Url;
    str = str.substring(1, str.length); // 获取URL中?之后的字符（去掉第一位的问号）
    // 以&分隔字符串，获得类似name=xiaoli这样的元素数组
    var arr = str.split("&");
    var obj = new Object();

    // 将每一个数组元素以=分隔并赋给obj对象 
    for (var i = 0; i < arr.length; i++) {
        var tmp_arr = arr[i].split("=");
        obj[decodeURIComponent(tmp_arr[0])] = decodeURIComponent(tmp_arr[1]);
    }
    return obj[key];
  }
  // console.log('getSearchString',getSearchString('parentUserId',window.location.search))
  $('#btn').on('click',function(e){
    e.stopPropagation();
    var mobile = $('#mobild').val();
    if(!mobile){
      alert('请输入手机号')
    }else{
      var regPhone = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
      if(!regPhone.test(mobile)){
        alert('请输入正确的手机号')
      }else{
        sendMsg();
      }
    }
  });
  function openApp(src) {
    // 通过iframe的方式试图打开APP，如果能正常打开，会直接切换到APP，并自动阻止a标签的默认行为
    // 否则打开a标签的href链接
    var ifr = document.createElement("iframe");
    ifr.src = src;
    ifr.style.display = "none";
    document.body.appendChild(ifr);
    window.setTimeout(function() {
      document.body.removeChild(ifr);
    }, 2000);
  }
  $("#openApp").on('click',function(e){
    e.preventDefault();//阻止默认行为
    var u = navigator.userAgent,
        app = navigator.appVersion;
    var d = new Date();
    var t0 = d.getTime();
    var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
    var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    let DownLoadApk = 'https://find-server.oss-cn-hangzhou.aliyuncs.com/picture/find.apk';
    if (isAndroid) {
      //Android   有打开app
      $('body').append("<iframe src='findit://' style='display:none' target='' ></iframe>");//target为空防止在当前页面刷新
      setTimeout(function(){window.location = DownLoadApk},600);
      
    } else if (isIOS) {
      //IOS
      alert("暂无ios版的应用");
    }
  })
  function sendMsg(){
    var parentUserId = getSearchString('parentUserId',window.location.search);
    var data = {
        parentUserId:parentUserId,
        mobile:$('#mobild').val().trim()
      }
    $.ajax({
      // url:'https://zuwozf.com/findtest/find-server/app/invite/binding',
      url:'https://xyzhaoyizhao.com/test/find-server/app/invite/binding',
      type:'post',
      dataType:"json",
      contentType: "application/json;charset=UTF-8",
      data:JSON.stringify(data),
      success:function(res){
        console.log('res',res)
        if(res.status == 0 ){
          $('.downloadApp').show();
        }else if(res.status == 1 || res.status == 2){
          $('.openApp').show();
        }else{
          alert(res.msg)
        }
      },
      error:function(err){
        console.log('err',err)
      }
    })
  }
</script>
</html>
